/**
 *====================================================
 * 文件名称: PickupInventoryServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年11月26日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.PickupInventoryEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;

/**
 * @ClassName: PickupInventoryServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年11月26日 15:52:17
 */
@Implements(PickupInventoryService.class)
public class PickupInventoryServiceImpl implements PickupInventoryService {

	@Override
	public Long createPickupInventory(PickupInventoryEntity entity) {
		PersistUtil.insert(entity);
		return entity.getPickupInventoryId();
	}

	@Override
	public void renovatePickupInventory(PickupInventoryEntity persist) {
		PersistUtil.update(persist);
	}

	@Override
	public void deletePickupInventory(Long pickupInventoryId) {
		PersistUtil.delete(PickupInventoryEntity.class, pickupInventoryId);
	}

	@Override
	public PickupInventoryEntity inquirePickupInventory(Long pickupId, Long inventoryId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(PickupInventoryEntity.class);
		criteria.add(Restrictions.eq("pickupId", pickupId));
		criteria.add(Restrictions.eq("inventoryId", inventoryId));
		List<PickupInventoryEntity> results = PersistUtil.get(criteria);
		if (results.isEmpty()) {
			return null;
		}
		return results.get(0);
	}

	@Override
	public List<PickupInventoryEntity> inquirePickupInventoryList(Long pickupId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(PickupInventoryEntity.class);
		criteria.add(Restrictions.eq("pickupId", pickupId));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<Long> inquirePickupInventoryIdList(Long pickupId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(PickupInventoryEntity.class);
		criteria.add(Restrictions.eq("pickupId", pickupId));
		criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("inventoryId")));
		return PersistUtil.get(criteria);
	}

}
